package com.dq.rbac.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @project: rbac
 * @ClassName: MvcConfig
 * @author: dq
 * @creat: 2022/12/26 12:59
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Value("${avater.prePath}")
    public String ABSOLUTE_PATH;

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedMethods("*")
                .allowedOrigins("*")
                .allowCredentials(true);
    }

    //虚拟映射URL
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/image/userAvatar/**").addResourceLocations("file:"+ABSOLUTE_PATH);
    }
}
